home *** CD-ROM | disk | FTP | other *** search
/ JavaScript CD Cookbook / JavaScript CD Cookbook.iso / mac / MACFILES / MMEDIA / MUSIC-OBJECT.JS < prev    next >
Encoding:
JavaScript  |  1997-09-21  |  17.8 KB  |  673 lines  |  [TEXT/LMAN]

  1. //***************************************
  2. //* musicObject code 1.6
  3. //* written by C. van Rensburg                    
  4. //*
  5. //* © Copyright 1996,1997 Headspace, Inc.
  6. //* All  Rights Reserved
  7. //***************************************
  8.  
  9. function mo_play (p1,p2) {
  10.     if (this.ready) {
  11.         clearTimeout (this.fadeTimeout);
  12.         if ((typeof (p1) == "boolean" || typeof (p1) == "number") && typeof (p2) == "string") {
  13.             document [this.pluginName].play (p1,p2);
  14.         } else if (typeof (p1) == "string" || typeof (p1) == "boolean" || typeof (p1) == "number") {
  15.             document [this.pluginName].play (p1);
  16.         } else {
  17.             document [this.pluginName].play ();
  18.         }
  19.     }
  20. }
  21.  
  22. function mo_playGroovoid (p1,p2) {
  23.     this.play (p1,"groovoid://" + p2);
  24. }
  25.  
  26. function mo_stop (fade) {
  27.     with (this) {
  28.         if (ready) {
  29.             clearTimeout (fadeTimeout);
  30.             if (typeof (fade) != "boolean") {
  31.                 document [pluginName].stop ();
  32.             } else {
  33.                 document [pluginName].stop (fade);
  34.             }
  35.         }
  36.     }
  37. }
  38.  
  39. function mo_pauseAtZero () {
  40.     with (this) {
  41.         if (ready) {
  42.             if (getVolume () == 0) {
  43.                 pause ();
  44.                 clearTimeout (fadeTimeout);
  45.             } else {
  46.                 pauseTimeout = setTimeout (name + '.pauseAtZero ()',500);
  47.             }
  48.         }
  49.     }
  50. }
  51.  
  52. function mo_pause (fade) {
  53.     with (this) {
  54.         if (ready) {
  55.             if (typeof (fade) != "boolean") {
  56.                 clearTimeout (fadeTimeout);
  57.                 document [pluginName].pause ();
  58.             } else if (fade) {
  59.                 fadeFromTo (getVolume (),0);
  60.                 pauseAtZero ();
  61.             } else {
  62.                 clearTimeout (fadeTimeout);
  63.                 document [pluginName].pause ();
  64.             }
  65.         }
  66.     }
  67. }
  68.  
  69. function mo_setLoop (state) {
  70.     if (this.ready) {document [this.pluginName].setLoop (state)}
  71. }
  72.  
  73. function mo_setAutostart (state) {
  74.     if (this.ready) {document [this.pluginName].setAutostart (state)}
  75. }
  76.  
  77. function mo_fadeTo (toValue) {
  78.     if (this.ready) {document [this.pluginName].fade_to (toValue)}
  79. }
  80.  
  81. function mo_fadeFromTo (fromValue,toValue) {
  82.     if (this.ready) {document [this.pluginName].fade_from_to (fromValue,toValue)}
  83. }
  84.  
  85. function mo_setReady (initFunction) {
  86.     with (this) {
  87.         if (document [pluginName] != null) {
  88.             ready = true;
  89.             eval (initFunction);
  90.         } else {
  91.             setTimeout (name + '.setReady ("' + initFunction + '")',500);
  92.         }
  93.     }
  94. }
  95.  
  96. function mo_setMonophonic (channelNo,state) {
  97.     with (this) {
  98.         if (channelNo == 0) {
  99.             for (var channelCount = 1; channelCount <= 16; channelCount++) {
  100.                 monophonic [channelCount-1] = state;
  101.             }
  102.         } else {
  103.             monophonic [channelNo-1] = state;
  104.         }
  105.     }
  106. }
  107.  
  108. function mo_getMonophonic (channelNo) {
  109.     with (this) {
  110.         if (channelNo >= 1 && channelNo <= 16) {
  111.             return monophonic [channelNo-1];
  112.         } else {
  113.             return false;
  114.         }
  115.     }
  116. }
  117.  
  118. function mo_noteOn (channelNo,p2,p3,p4,p5) {
  119.     with (this) {
  120.         if (ready) {
  121.             if (monophonic [channelNo-1]) {
  122.                 noteOff (channelNo,notesOn [channelNo],127);
  123.             }
  124.             if (p4 != null && p5 != null) {
  125.                 notesOn [channelNo] = p4;
  126.                 document [pluginName].noteOn (channelNo,p2,p3,p4,p5);
  127.             } else {
  128.                 notesOn [channelNo] = p2;
  129.                 document [pluginName].noteOn (channelNo,p2,p3);
  130.             }
  131.         }
  132.     }
  133. }
  134.  
  135. function mo_noteOff (channelNo,noteNo) {
  136.     with (this) {
  137.         if (ready) {
  138.             notesOn [channelNo] = 0;
  139.             document [pluginName].noteOff (channelNo,noteNo,127)
  140.         }
  141.     }
  142. }
  143.  
  144. function mo_playNote (channelNo,p2,p3,p4,p5,p6) {
  145.     with (this) {
  146.         if (ready) {
  147.             if (monophonic [channelNo-1]) {
  148.                 noteOff (channelNo,notesOn [channelNo],127);
  149.             }
  150.             if (p5 != null & p6 != null) {
  151.                 noteOn (channelNo,p2,p3,p4,p5,p6);
  152.                 setTimeout (this.name + '.noteOff (' + channelNo + ',' + p4 + ',' + p5 + ')',p6);
  153. //                notesOn [channelNo] = p4;
  154. //                setProgram (channelNo,p2,p3);
  155. //                document [this.pluginName].playNote (channelNo,p4,p5,p6);
  156.             } else {
  157.                 noteOn (channelNo,p2,p3,p4);
  158.                 setTimeout (this.name + '.noteOff (' + channelNo + ',' + p2 + ',' + p3 + ')',p4);
  159. //                notesOn [channelNo] = p2;
  160. //                document [this.pluginName].playNote (channelNo,p2,p3,p4);
  161.             }
  162.         }
  163.     }
  164. }
  165.  
  166. function mo_playSample (sampleName,pan,volume) {
  167.     if (this.ready) {document [this.pluginName].playSample (sampleName,pan,volume)}
  168. }
  169.  
  170. function mo_setGlobalMute (muteState) {
  171.     if (this.ready) {document [this.pluginName].setGlobalMute (muteState)}
  172. }
  173.  
  174. function mo_setPanelDisplay (displayType) {
  175.     if (this.ready) {document [this.pluginName].setPanelDisplay (displayType)}
  176. }
  177.  
  178. function mo_setPanelMode (panelMode) {
  179.     if (this.ready) {document [this.pluginName].setPanelMode (panelMode)}
  180. }
  181.  
  182. function mo_setVolume (volume) {
  183.     if (this.ready) {document [this.pluginName].setVolume (volume)}
  184. }
  185.  
  186. function mo_setTranspose (transpose) {
  187.     if (this.ready) {document [this.pluginName].setTranspose (transpose)}
  188. }
  189.  
  190. function mo_setTempo (tempo) {
  191.     if (this.ready) {document [this.pluginName].setTempo (tempo)}
  192. }
  193.  
  194. function mo_setReverbType (reverbType) {
  195.     if (this.ready) {document [this.pluginName].setReverbType (reverbType)}
  196. }
  197.  
  198. function mo_setController (channelNo,controllerNo,controllerValue) {
  199.     if (this.ready) {document [this.pluginName].setController (channelNo,controllerNo,controllerValue)}
  200. }
  201.  
  202. function mo_setProgram (channelNo,p2,p3) {
  203.     if (this.ready) {
  204.         with (this) {
  205.             if (p3 != null) {
  206.                 document [this.pluginName].setProgram (channelNo,p2, p3);
  207.             } else {
  208.                 document [this.pluginName].setProgram (channelNo,p2);
  209.             }
  210.         }
  211.     }
  212. }
  213.  
  214. function mo_setTrackMute (trackNo,state) {
  215.     if (this.ready) {document [this.pluginName].setTrackMute (trackNo,state)}
  216. }
  217.  
  218. function mo_setChannelMute (channelNo,state) {
  219.     if (this.ready) {document [this.pluginName].setChannelMute (channelNo,state)}
  220. }
  221.  
  222. function mo_setTrackSolo (trackNo,state) {
  223.     if (this.ready) {document [this.pluginName].setTrackSolo (trackNo,state)}
  224. }
  225.  
  226. function mo_setChannelSolo (channelNo,state) {
  227.     if (this.ready) {document [this.pluginName].setChannelSolo (channelNo,state)}
  228. }
  229.  
  230. function mo_getPanelDisplay () {
  231.     if (this.ready) {return document [this.pluginName].getPanelDisplay ()} else {return ""}
  232. }
  233.  
  234. function mo_getPanelMode (panelMode) {
  235.     if (this.ready) {return document [this.pluginName].getPanelMode ()} else {return ""}
  236. }
  237.  
  238. function mo_getVolume () {
  239.     if (this.ready) {return document [this.pluginName].GetVolume ()} else {return 100}
  240. }
  241.  
  242. function mo_getAutostart () {
  243.     if (this.ready) {return document [this.pluginName].getAutostart ()} else {return false}
  244. }
  245.  
  246. function mo_getLoop () {
  247.     if (this.ready) {return document [this.pluginName].getLoop ()} else {return false}
  248. }
  249.  
  250. function mo_getReverbType () {
  251.     if (this.ready) {return document [this.pluginName].getReverbType ()} else {return 0}
  252. }
  253.  
  254. function mo_getTempo () {
  255.     if (this.ready) {return document [this.pluginName].getTempo ()} else {return 120}
  256. }
  257.  
  258. function mo_getTranspose () {
  259.     if (this.ready) {return document [this.pluginName].getTranspose ()} else {return 0}
  260. }
  261.  
  262. function mo_getController (channelNo,controllerNo) {
  263.     if (this.ready) {return document [this.pluginName].getController (channelNo,controllerNo)} else {return 0}
  264. }
  265.  
  266. function mo_getProgram (channelNo) {
  267.     if (this.ready) {return document [this.pluginName].getProgram (channelNo)} else {return 0}
  268. }
  269.  
  270. function mo_getTrackMute (trackNo) {
  271.     if (this.ready) {return document [this.pluginName].getTrackMute (trackNo)} else {return false}
  272. }
  273.  
  274. function mo_getChannelMute (channelNo) {
  275.     if (this.ready) {return document [this.pluginName].getChannelMute (channelNo)} else {return false}
  276. }
  277.  
  278. function mo_getTrackSolo (trackNo) {
  279.     if (this.ready) {return document [this.pluginName].getTrackSolo (trackNo)} else {return false}
  280. }
  281.  
  282. function mo_getChannelSolo (channelNo) {
  283.     if (this.ready) {return document [this.pluginName].getChannelSolo (channelNo)} else {return false}
  284. }
  285.  
  286. function mo_getInfo (infoField) {
  287.     if (this.ready) {return document [this.pluginName].getInfo (infoField)} else {return ''}
  288. }
  289.  
  290. function mo_isPaused () {
  291.     if (this.ready) {return document [this.pluginName].IsPaused ()} else {return false}
  292. }
  293.  
  294. function mo_isPlaying () {
  295.     if (this.ready) {return document [this.pluginName].IsPlaying ()} else {return false}
  296. }
  297.  
  298. function mo_isReady () {
  299.     return this.ready;
  300. }
  301.  
  302. function mo_getNoteNumber (noteName) {
  303.     noteOffset = this.noteNumbers [noteName.substring (0,1).toLowerCase ()];
  304.     if (noteOffset == null) {
  305.         return 0;
  306.     } else {
  307.         sharpFlatOffset = 0;
  308.         sharpFlatPos = noteName.indexOf ('b',1);
  309.         if (sharpFlatPos == -1) {
  310.             sharpFlatPos = noteName.indexOf ('#',1);
  311.             if (sharpFlatPos == -1) {
  312.                 sharpFlatPos = 0;
  313.             } else {
  314.                 sharpFlatOffset = 1;
  315.             }
  316.         } else {
  317.             sharpFlatOffset = -1;
  318.         }
  319.         octaveNo = noteName.substring (sharpFlatPos+1,noteName.length) - 0;
  320.         return 12 + octaveNo * 12 + noteOffset + sharpFlatOffset;
  321.     }
  322. }
  323.  
  324. function mo_getNoteName (noteNumber) {
  325.     return this.noteNames [noteNumber % 12] + (Math.floor (noteNumber / 12) - 1) + "";
  326. }
  327.  
  328. function mo_getVersion () {
  329.     return ('1.5');
  330. }
  331.  
  332. function mo_getPlatform () {
  333.     return (navigator.userAgent);
  334. }
  335.  
  336. function voice_define (bankNo,programNo,noteNo,velocityVal,volumeVal,panVal) {
  337.     this.bankNo = bankNo;
  338.     this.programNo = programNo;
  339.     this.noteNo = noteNo;
  340.     this.velocityVal = velocityVal;
  341.     this.volumeVal = volumeVal;
  342.     this.panVal = panVal;
  343.     this.flagged = false;
  344. }
  345.  
  346. function voice (bankNo,programNo,noteNo,velocityVal,volumeVal,panVal) {
  347.     this.bankNo = bankNo;
  348.     this.programNo = programNo;
  349.     this.noteNo = noteNo;
  350.     this.velocityVal = velocityVal;
  351.     this.volumeVal = volumeVal;
  352.     this.panVal = panVal;
  353.     this.flagged = false;
  354.     this.define = voice_define;
  355. }
  356.  
  357. function mo_sceneStart () {
  358.     with (this) {
  359.         totalNewVoices = 0;
  360.     }
  361. }
  362.  
  363. function mo_sceneCheckVoiceAllocation (newVoiceNo) {
  364.     with (this) {
  365.         for (voiceNo = 1; voiceNo <= 16; voiceNo++) {
  366.             if (voices [voiceNo-1] != null) {
  367.                 if (
  368.                     newVoices [newVoiceNo-1].bankNo == voices [voiceNo-1].bankNo &&
  369.                     newVoices [newVoiceNo-1].programNo == voices [voiceNo-1].programNo &&
  370.                     newVoices [newVoiceNo-1].noteNo == voices [voiceNo-1].noteNo &&
  371.                     newVoices [newVoiceNo-1].velocityVal == voices [voiceNo-1].velocityVal
  372.                 ) {
  373.                     voices [voiceNo-1].flagged = true;
  374.                     newVoices [newVoiceNo-1].flagged = true;
  375.                     voices [voiceNo-1].volumeVal = newVoices [newVoiceNo-1].volumeVal;
  376.                     voices [voiceNo-1].panVal = newVoices [newVoiceNo-1].panVal;
  377.                     setController (voiceNo,7,voices [voiceNo-1].volumeVal);
  378.                     setController (voiceNo,10,voices [voiceNo-1].panVal);
  379.                 }
  380.             }
  381.         }
  382.     }
  383. }
  384.  
  385. function mo_sceneAllocateVoice (newVoiceNo) {
  386.     with (this) {
  387.         if (!newVoices [newVoiceNo-1].flagged) {
  388.             for (voiceNo = 1; voiceNo <= 16; voiceNo++) {
  389.                 with (newVoices [newVoiceNo-1]) {
  390.                     if (!flagged) {
  391.                         voices [voiceNo-1].define (bankNo,programNo,noteNo,velocityVal,volumeVal,panVal);
  392.                         flagged = true;
  393.                         setController (voiceNo,7,volumeVal);
  394.                         setController (voiceNo,10,panVal);
  395.                         noteOn (voiceNo,bankNo,programNo,noteNo,velocityVal);
  396.                         break;
  397.                     }
  398.                 }
  399.             }
  400.         }
  401.     }
  402. }
  403.  
  404. function mo_sceneEnd () {
  405.     with (this) {
  406.         for (voiceNo = 1; voiceNo <= 16; voiceNo++) {
  407.             voices [voiceNo-1].flagged = false;
  408.         }
  409.         for (newVoiceNo = 1; newVoiceNo <= totalNewVoices; newVoiceNo++) {
  410.             sceneCheckVoiceAllocation (newVoiceNo);
  411.         }
  412.         for (voiceNo = 1; voiceNo <= 16; voiceNo++) {
  413.             with (voices [voiceNo-1]) {
  414.                 if (!flagged && bankNo != -1) {
  415.                     noteOff (voiceNo,noteNo,velocityVal);
  416.                     bankNo = -1;
  417.                 }
  418.             }
  419.         }
  420.         for (newVoiceNo = 1; newVoiceNo <= totalNewVoices; newVoiceNo++) {
  421.             sceneAllocateVoice (newVoiceNo);
  422.         }
  423.     }
  424. }
  425.  
  426. function mo_sceneVoice (bankNo,programNo,noteNo,velocityVal,volumeVal,panVal) {
  427.     with (this) {
  428.         totalNewVoices++;
  429.         newVoices [totalNewVoices-1].define (bankNo,programNo,noteNo,velocityVal,volumeVal,panVal);
  430.     }
  431. }
  432.  
  433. function mo_sceneImmediateVoice (bankNo,programNo,noteNo,velocityVal,volumeVal,panVal) {
  434.     with (this) {
  435.         sceneVoice (bankNo,programNo,noteNo,velocityVal,volumeVal,panVal);
  436.         sceneCheckVoiceAllocation (totalNewVoices);
  437.         sceneAllocateVoice (totalNewVoices);
  438.         totalNewVoices--;
  439.     }
  440. }
  441.  
  442. function musicObject (name) {
  443.     this.fadeTimeout = setTimeout ('//',0);
  444.  
  445.     this.name = name;
  446.     this.pluginName = name + "Plugin";
  447.     this.ready = false;
  448.  
  449.     //****************************
  450.     // reflected plug-in functions
  451.  
  452.     this.play = mo_play;
  453.     this.playGroovoid = mo_playGroovoid;
  454.     this.stop = mo_stop;
  455.     this.pause = mo_pause;
  456.     this.setLoop = mo_setLoop;
  457.     this.fadeTo = mo_fadeTo;
  458.     this.fade_to = mo_fadeTo;
  459.     this.fadeFromTo = mo_fadeFromTo;
  460.     this.fade_from_to = mo_fadeFromTo;
  461.     this.setAutostart = mo_setAutostart;
  462.     
  463.     this.playNote = mo_playNote;
  464.     this.noteOn = mo_noteOn;
  465.     this.noteOff = mo_noteOff;
  466.     this.playSample = mo_playSample;
  467.  
  468.     this.setPanelDisplay = mo_setPanelDisplay;
  469.     this.setPanelMode = mo_setPanelMode;
  470.     this.setGlobalMute = mo_setGlobalMute;
  471.     this.setVolume = mo_setVolume;
  472.     this.setTranspose = mo_setTranspose;
  473.     this.setController = mo_setController;
  474.     this.setProgram = mo_setProgram;
  475.     this.setTempo = mo_setTempo;
  476.     this.setReverbType = mo_setReverbType;
  477.     this.setTrackMute = mo_setTrackMute;
  478.     this.setChannelMute = mo_setChannelMute;
  479.     this.setTrackSolo = mo_setTrackSolo;
  480.     this.setChannelSolo = mo_setChannelSolo;
  481.  
  482.     this.getPanelDisplay = mo_getPanelDisplay;
  483.     this.getPanelMode = mo_getPanelMode;
  484.     this.getVolume = mo_getVolume;
  485.     this.GetVolume = mo_getVolume;
  486.     this.getAutostart = mo_getAutostart;
  487.     this.getLoop = mo_getLoop;
  488.     this.getReverbType = mo_getReverbType;
  489.     this.getTempo = mo_getTempo;
  490.     this.getTranspose = mo_getTranspose;
  491.     this.getController = mo_getController;
  492.     this.getProgram = mo_getProgram;
  493.     this.getTrackMute = mo_getTrackMute;
  494.     this.getChannelMute = mo_getChannelMute;
  495.     this.getTrackSolo = mo_getTrackSolo;
  496.     this.getChannelSolo = mo_getChannelSolo;
  497.     this.getInfo = mo_getInfo;
  498.     this.isPaused = mo_isPaused;
  499.     this.IsPaused = mo_isPaused;
  500.     this.isPlaying = mo_isPlaying;
  501.     this.IsPlaying = mo_isPlaying;
  502.     this.isReady = mo_isReady;
  503.     this.IsReady = mo_isReady;
  504.  
  505.     //******** extended authoring API functions *********
  506.  
  507.     this.setReady = mo_setReady;
  508.     this.setMonophonic = mo_setMonophonic;
  509.     this.getMonophonic = mo_getMonophonic;
  510.     this.playNotePlus = mo_playNote;
  511.     this.pauseAtZero = mo_pauseAtZero;
  512.     this.getNoteNumber = mo_getNoteNumber;
  513.     this.getNoteName = mo_getNoteName;
  514.     this.getVersion = mo_getVersion;
  515.     this.getPlatform = mo_getPlatform;
  516.  
  517.     this.sceneCheckVoiceAllocation = mo_sceneCheckVoiceAllocation;
  518.     this.sceneAllocateVoice = mo_sceneAllocateVoice;
  519.     this.sceneStart = mo_sceneStart;
  520.     this.sceneVoice = mo_sceneVoice;
  521.     this.sceneImmediateVoice = mo_sceneImmediateVoice;
  522.     this.sceneEnd = mo_sceneEnd;
  523.     
  524.     //***************************************************
  525.     
  526.     this.monophonic = new Array (false,false,false,false,false,false,false,false,false,false,false,false,false,false,false);
  527.     this.notesOn = new Array (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  528.  
  529.     this.noteNumbers = new Array ();
  530.     this.noteNumbers ['c'] = 0;
  531.     this.noteNumbers ['d'] = 2;
  532.     this.noteNumbers ['e'] = 4;
  533.     this.noteNumbers ['f'] = 5;
  534.     this.noteNumbers ['g'] = 7;
  535.     this.noteNumbers ['a'] = 9;
  536.     this.noteNumbers ['b'] = 11;
  537.     
  538.     this.noteNames = new Array ("C","C#","D","D#","E","F","F#","G","G#","A","A#","B");
  539.  
  540.     this.voices = new Array ();
  541.     this.newVoices = new Array ();
  542.     for (voiceNo = 1; voiceNo <= 16; voiceNo++) {
  543.         this.voices [voiceNo-1] = new voice (0,0,0,0,0,0);
  544.         this.newVoices [voiceNo-1] = new voice (0,0,0,0,0,0);
  545.     }
  546.     this.totalNewVoices = 0;
  547. }
  548.  
  549. //***********
  550. //* random ()
  551.  
  552. today = new Date ();
  553.  
  554. function random (range) {
  555.     return (Math.round (today.getTime () / 100) % range) + 1;
  556. }
  557.  
  558. //***********************
  559. //* randomPP object class
  560.  
  561. function randomPP_selectNext () {
  562.     flagsFound = 0;
  563.     with (Math) {randomFlag = round (random () * (this.flagsRemaining - 1)) + 1}
  564.     for (var flagNo = 1; flagNo <= this.totalFlags; flagNo++) {
  565.         if (!this.flags [flagNo]) {
  566.             flagsFound++;
  567.             if (flagsFound == randomFlag) {
  568.                 randomFlag = flagNo;
  569.                 this.flags [randomFlag] = true;
  570.                 break;
  571.             }
  572.         }
  573.     }
  574.     this.flagsSelected++;
  575.     this.flagsRemaining--;
  576.     if (this.flagsSelected == this.totalFlags) {
  577.         this.flagsSelected = 0;
  578.         this.flagsRemaining = this.totalFlags;
  579.         for (var flagNo = 1; flagNo <= this.totalFlags; flagNo++) {
  580.             this.flags [flagNo] = false;
  581.         }
  582.     }
  583.     return randomFlag;
  584. }
  585.  
  586. function randomPP (range) {
  587.     this.flags = new Array (range)
  588.     this.totalFlags = range;
  589.     this.flagsSelected = 0;
  590.     this.flagsRemaining = this.totalFlags;
  591.     this.selectNext = randomPP_selectNext;
  592.     for (var flagNo = 1; flagNo <= this.totalFlags; flagNo++) {
  593.         this.flags [flagNo] = false;
  594.     }
  595. }
  596.  
  597. //*******************
  598. //* randomFromList ()
  599.  
  600. function randomFromList (prefix,suffix) {
  601.     totalItems = randomFromList.arguments.length - 2;
  602.     if (totalItems == 0) {
  603.         return prefix + suffix;
  604.     } else {
  605.         randomItemNo = random (totalItems);
  606.         return prefix + randomFromList.arguments [randomItemNo + 1] + suffix;
  607.     }
  608. }
  609.  
  610. //*************
  611. //* mimeType ()
  612.  
  613. extMIME = new Array ();
  614.  
  615. extMIME ['mid'] = 'audio/midi';
  616. extMIME ['midi'] = 'audio/midi';
  617. extMIME ['rmf'] = 'audio/rmf';
  618. extMIME ['wav'] = 'audio/wav';
  619. extMIME ['au'] = 'audio/basic';
  620. extMIME ['aif'] = 'audio/aiff';
  621. extMIME ['aiff'] = 'audio/aiff';
  622. extMIME ['mod'] = 'audio/mod';
  623. extMIME ['m15'] = 'audio/mod';
  624. extMIME ['mtm'] = 'audio/mod';
  625. extMIME ['s3m'] = 'audio/mod';
  626. extMIME ['ult'] = 'audio/mod';
  627. extMIME ['xm'] = 'audio/mod';
  628.  
  629. function mimeType (fileName) {
  630.     returnVal = '';
  631.     delimPos = fileName.lastIndexOf ('.');
  632.     if (delimPos != -1) {
  633.         returnVal = extMIME [fileName.substring (delimPos + 1,fileName.length)];
  634.         if (returnVal == null) {returnVal = ''}
  635.     }
  636.     return returnVal;
  637. }
  638.  
  639. //***************
  640. //* hasBeatnik ()
  641.  
  642. hasBeatnikFlag = null;
  643.  
  644. function hasBeatnik () {
  645.     if (hasBeatnikFlag == null) {
  646.         hasBeatnikFlag = true;
  647.         with (navigator) {
  648.             if (userAgent.indexOf ('Mozilla/3.0') != -1 || userAgent.indexOf ('Mozilla/4.0') != -1) {
  649.                 hasBeatnikFlag = false;
  650.                 for (pluginNo = 1; pluginNo <= plugins.length && !hasBeatnikFlag; pluginNo++) {
  651.                     if (plugins [pluginNo-1].name.indexOf ('Beatnik') != -1) {
  652.                         hasBeatnikFlag = true;
  653.                     }
  654.                 }
  655.             }
  656.         }
  657.     }
  658.     return hasBeatnikFlag;
  659. }
  660.  
  661. //***************
  662. //* magicEmbed ()
  663.  
  664. function magicEmbed (embedURL) {
  665.     with (document) {
  666.         if (hasBeatnik ()) {
  667.             writeln ('<EMBED SRC="' + embedURL + '" TYPE="audio/rmf" WIDTH=144 HEIGHT=60 AUTOSTART=TRUE LOOP=TRUE>');
  668.         } else {
  669.             writeln ('<A HREF="http://www.headspace.com/beatnik/?plug-in" TARGET="_top"><IMG SRC="http://www.headspace.com/beatnik/images/get-beatnik-plugin.gif" WIDTH=144 HEIGHT=60 BORDER=0 ALT="Get the Beatnik Plug-in NOW!"></A>');
  670.         }
  671.     }
  672. }
  673.